package com.example.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class ContextServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1. 获取web.xml文件中<context-param>中配置的信息
        ServletContext servletContext = this.getServletContext();
        String userName = servletContext.getInitParameter("userName");
        String password = servletContext.getInitParameter("password");
        System.out.println("userName = " + userName);
        System.out.println("password = " + password);

        // 2. 获取当前工程路径 ，格式：/工程路径
        String contextPath = servletContext.getContextPath();
        System.out.println("contextPath = " + contextPath);

        // 3. 获取工程部署在服务器硬盘上的绝对路径
        String realPath = servletContext.getRealPath("/");
        System.out.println("realPath = " + realPath);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
